//
//  Application.swift
//  CooperSwift
//
//  Created by 计海峰 on 2019/9/5.
//  Copyright © 2019 Mac. All rights reserved.
//

import Foundation
import UIKit

public extension UIApplication {
    
    // 当前vc
    class func currentVC(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
        if let nav = base as? UINavigationController {
            return currentVC(base: nav.visibleViewController)
        }
        if let tab = base as? UITabBarController {
            return currentVC(base: tab.selectedViewController)
        }
        if let presented = base?.presentedViewController {
            return currentVC(base: presented)
        }
        return base
    }
    
}
